--无敌时可以回血
AddComponentPostInit("health", function(Health, inst)
    if not inst:HasTag("player") then
        return
    end

    Health.i5o_DoDelta = Health.DoDelta
    function Health:DoDelta(amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb, ...)
        if amount > 0 then
            ignore_invincible = true
        end
        return self:i5o_DoDelta(amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb, ...)
    end
end)
--无敌时可以回饱食度
AddComponentPostInit("hunger", function(Hunger, inst)
    if not inst:HasTag("player") then
        return
    end

    Hunger.i5o_DoDelta = Hunger.DoDelta
    function Hunger:DoDelta(delta, overtime, ignore_invincible, ...)
        if delta > 0 then
            ignore_invincible = true
        end
        return self:i5o_DoDelta(delta, overtime, ignore_invincible, ...)
    end
end)

--无敌时理智继续更新
AddComponentPostInit("sanity", function(Sanity, inst)
    if not inst:HasTag("player") then
        return
    end

    Sanity.i5o_OnUpdate = Sanity.OnUpdate
    function Sanity:OnUpdate(dt, ...)   
        if self.inst.components.health:IsInvincible() and   --原版没有判空
        not (
            self.inst:HasTag("spawnprotection") 
            or self.inst.sg:HasStateTag("sleeping")
            or self.inst.is_teleporting
            or (self.ignore and self.redirect == nil)
        ) then
            self:UpdateMode_Internal() --since we may not know when lunacy sources are removed
            self:Recalc(dt, ...)
        else
            return self:i5o_OnUpdate(dt, ...)
        end
    end
end)